<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport"
			content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>个人简历</title>
		<link rel="stylesheet" href="../css/personal_resume.css">
		<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
		<link rel="shortcut icon" href="../img/title/招聘求职.png" type="image/x-icon">
	</head>
	<body>
		<div id="app">
			<div class="header">
				<div class="header_left">
					<img src="../img/main/招聘会.png">
					<a href="./main.html">&nbsp;校园兼职管理</a>
				</div>
				<div class="header_center">
					<ul>
						<li><a href="./main.html">主页</a></li>
						<li><a href="./work_list.html">职位</a></li>
						<li><a href="./news.html">校园新闻</a></li>
					</ul>
				</div>
				<div class="header_right">
					<el-button @click="loginBtn" type="success" icon="el-icon-user-solid">登录</el-button>
					<el-button @click="registerBtn" type="success" icon="el-icon-takeaway-box">注册</el-button>
				</div>
			</div>
			<div class="section">
				<div class="section_1">添加简历</div>
				<div class="section_2">首页 > 个人简历</div>
			</div>
			<div class="content">
				<div class="content_form">
					<div class="content_form_header">
						<p style="color: aliceblue;font-size: 23px;position: relative;top: 18px;left: 18px;">添加/修改简历</p>
					</div>
					<div class="content_form_section">
						<div class="content_form_section_item">
							<p style="font-weight: 450;margin-top: 6px;">姓名:</p>
							<el-input v-model="resume.name" maxlength="20" placeholder="姓名"></el-input>
						</div>
						<div class="content_form_section_item">
							<p style="font-weight: 450;margin-top: 6px;">年龄:</p>
							<el-input v-model="resume.age" maxlength="2" placeholder="年龄"></el-input>
						</div>
						<div class="content_form_section_item">
							<p style="font-weight: 450;margin-top: 6px;">期望薪资:</p>
							<el-input v-model="resume.expectation_price" maxlength="20"  placeholder="期望薪资"></el-input>
						</div>
						<div class="content_form_section_item">
							<p style="font-weight: 450;margin-top: 6px;">学历:</p>
							  <el-select v-model="resume.official" clearable placeholder="请选择">
							    <el-option
							      v-for="item in options"
							      :key="item.value"
							      :label="item.label"
							      :value="item.value">
							    </el-option>
							  </el-select>
						</div>
						<div class="content_form_section_item">
							<p style="font-weight: 450;margin-top: 6px;">工作性质:</p>
							  <el-select v-model="resume.type" clearable placeholder="请选择">
							    <el-option
							      v-for="item in options1"
							      :key="item.value"
							      :label="item.label"
							      :value="item.value">
							    </el-option>
							  </el-select>
						</div>
						<div class="content_form_section_item">
							<p style="font-weight: 450;margin-top: 6px;">期望城市:</p>
							<el-input v-model="resume.expectation_city" maxlength="20" placeholder="期望城市"></el-input>
						</div>
						<div class="content_form_section_item">
							<p style="font-weight: 450;margin-top: 6px;">毕业院校:</p>
							<el-input v-model="resume.over_university" maxlength="20" placeholder="毕业院校"></el-input>
						</div>
						<div class="content_form_section_item">
							<p style="font-weight: 450;margin-top: 6px;">专业:</p>
							<el-input v-model="resume.university_majoy" maxlength="20" placeholder="专业"></el-input>
						</div>
						<div class="content_form_section_item">
							<p style="font-weight: 450;margin-top: 6px;">毕业时间:</p>
							    <el-date-picker
							      v-model="resume.over_time"
							      type="date"
							      placeholder="毕业时间" style="width: 100%;">
							    </el-date-picker>
						</div>
						<div class="content_form_section_itemLong">
							<p style="font-weight: 450;margin-top: 6px;">是否是党员:</p>
							  <el-select v-model="resume.party_status" clearable placeholder="是否是党员">
							    <el-option
							      v-for="item in options2"
							      :key="item.value"
							      :label="item.label"
							      :value="item.value">
							    </el-option>
							  </el-select>
						</div>
						<div class="content_form_section_itemLong">
							<p style="font-weight: 450;margin-top: 6px;">求职状态:</p>
							  <el-select v-model="resume.work_status" clearable placeholder="求职状态">
							    <el-option
							      v-for="item in options3"
							      :key="item.value"
							      :label="item.label"
							      :value="item.value">
							    </el-option>
							  </el-select>
						</div>
						<div class="content_form_section_itemLong">
							<p style="font-weight: 450;margin-top: 6px;">手机号:</p>
							<el-input v-model="resume.phone" maxlength="11" placeholder="手机号"></el-input>
						</div>
						<div class="content_form_section_itemLong">
							<p style="font-weight: 450;margin-top: 6px;">邮箱:</p>
							<el-input v-model="resume.email" maxlength="20" placeholder="邮箱"></el-input>
						</div>
						<div class="content_form_section_area">
							<p style="font-weight: 450;margin-top: 6px;">工作经历:</p>
							<el-input
							  type="textarea"
							  placeholder="工作经历"
							  v-model="resume.work_experience"
							  maxlength="255"
							  show-word-limit
							  rows="5"
							  style="font-size: 14.5px;"
							>
							</el-input>
						</div>
					</div>
					<div class="content_form_footer">
						<el-button @click="save" style="width:90%;" type="primary">保存/修改<i class="el-icon-upload el-icon--right"></i></el-button>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
	<script src="https://unpkg.com/element-ui/lib/index.js"></script>
	<script src="../js/jquery-3.6.1.js"></script>
	<script src="../js/axios-0.18.0.js"></script>
	<script src="../js/after_landing.js"></script>
	<script>
		const vm = new Vue({
			el: '#app',
			data() {
				return {
					options: [{
					  value: '高中及以下',
					  label: '高中及以下'
					}, {
					  value: '大专',
					  label: '大专'
					}, {
					  value: '本科',
					  label: '本科'
					}, {
					  value: '硕士',
					  label: '硕士'
					}],
					options1: [{
					  value: '工作',
					  label: '工作'
					}, {
					  value: '兼职',
					  label: '兼职'
					}, {
					  value: '实习',
					  label: '实习'
					}],
					options2: [{
					          value: '是',
					          label: '是'
					        }, {
					          value: '否',
					          label: '否'
					        }],
					options3: [{
					          value: '离职',
					          label: '离职'
					        }, {
					          value: '在职',
					          label: '在职'
					        }, {
					          value: '在校',
					          label: '在校'
					        }],
					userMsgList: [],
					//提交表单时的模型
					resume: {
						name: '',
						age: '',
						expectation_price : '',
						official: '',
						type: '',
						expectation_city: '',
						over_university: '',
						university_majoy: '',
						over_time: '',
						party_status: '',
						work_status: '',
						phone: '',
						email: '',
						work_experience: '',
						user_id : ''
					},
				}
			},
			async created() {
				let username = getCookie("cookie_username")
				if (username !== null && username.length > 0) {
					await axios.get('/users/' + username).then((resp) => {
						this.userMsgList = resp.data.data
						$('.header_center ul').append(
							`<li><a style="color: lawngreen;" href="./personal_resume.html">简历</a></li>`)
						$('.header_center ul').append(`<li><a href="./personal_center.html">个人中心</a></li>`)
						$('.header_right').empty()
						let url = this.userMsgList.user_image
						$(".header_right").append(
							`<img style="width: 7%;margin-right: 5px" src="${url}">${username}`);
						$(".header_right").append(
							`<a style="text-decoration: none;color: #77838e;margin-left: 5px" href="/logins/logout">注销</a>`
						);
					})
					await axios.get('/resumes/'+this.userMsgList.id).then((resp)=>{
						this.resume.phone = resp.data.data.phone;
						this.resume.email = resp.data.data.email;
						this.resume.name = resp.data.data.name;
						this.resume.age = resp.data.data.age;
						this.resume.expectation_price = resp.data.data.expectation_price;
						this.resume.official = resp.data.data.official;
						this.resume.type = resp.data.data.type;
						this.resume.expectation_city = resp.data.data.expectation_city;
						this.resume.over_university = resp.data.data.over_university;
						this.resume.university_majoy = resp.data.data.university_majoy;
						this.resume.over_time = resp.data.data.over_time;
						this.resume.party_status = resp.data.data.party_status;
						this.resume.work_status = resp.data.data.work_status;
						this.resume.work_experience = resp.data.data.work_experience;
						this.resume.user_id = resp.data.data.user_id;
					})
				} else {
					document.location.href = "login.html"
				}
			},

			methods:{
				loginBtn(){
					window.location.replace("/pages/login.html");
				},
				registerBtn() {
					document.location.href = "register.html"
				},
				save(){
					// let flag = /^[\d|\.]*$/.test(this.phone);
					// if (flag){
					// 	let myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
					// 	let regFlag = myreg.test(this.email)
					// 	if (!regFlag){
							this.loading = true
							// .....发请求
							if (this.resume.user_id === ''){
								this.resume.user_id = this.userMsgList.id
								//有用户信息但没有简历信息 insert
								axios.post('/resumes/insert',this.resume).then((resp)=>{
									if (resp.data.code === 300){
										setTimeout(()=>{
											this.$message.success('数据添加成功~');
										},1000)
										window.location.reload();
									} else {
										this.$message.error('要不咱再检查一下~');
									}
								})
							} else if (this.resume.user_id !== '') {
								this.loading = true;
								//有用户信息有简历信息 update
								axios.put('/resumes/update',this.resume).then((resp)=>{
									if (resp.data.code === 400){
										this.$message.success('数据修改成功~');
										window.location.reload();
									} else {
										this.$message.error('要不咱再检查一下~');
									}
								})
							}
							this.loading = false
					// 	} else {
					// 		this.$message.error('邮箱格式异常，请检查！')
					// 		this.email = ''
					// 	}
					// } else {
					// 	this.$message.error('手机号输入异常，请检查！')
					// 	this.phone = ''
					// }
				}
			}
		})
	</script>
</html>
